package me.zhengjie.utils;

import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Random;
import java.util.concurrent.atomic.AtomicLong;

public class OrderNoGenerator {
    private static final AtomicLong sequence = new AtomicLong(0);
    private static final Random random = new Random();

    public static String generate() {
        // 时间戳（精确到毫秒）
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String timestamp = sdf.format(new Date());

        // 3位随机数（防止并发重复）
        int randomNum = random.nextInt(900) + 100; // 100~999

        // 序列号（单机自增）
        long seq = sequence.incrementAndGet() % 1000;

        return timestamp + randomNum + String.format("%03d", seq);
    }
}
